package com.tianyi.sfzy1.controller;

import com.tianyi.sfzy1.domain.Lessonlist;
import com.tianyi.sfzy1.service.LessonlistService;
import com.tianyi.sfzy1.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/lessonlist")
public class LessonlistController {

    @Autowired
    private LessonlistService lessonlistService;


    /**
     * 通过课程id查询所有课程列表
     */
    @GetMapping
    public R findLesson(int courseId){
        List<Lessonlist> list=lessonlistService.findLesson(courseId);
        return R.ok(list);
    }

    /**
     * 点击购买根据课程id更改课程列表状态
     */
    @PutMapping
    public R update(int courseId){
        int i=lessonlistService.update(courseId);
        if (i>0){
            return R.ok(null);
        }else {
            return R.fail("更新失败");
        }
    }

}
